package com.fyzk.activity.lottery.jc.football;

import android.app.Activity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.fyzk.activity.lottery.zc.ZCFX_fx_lsjf;
import com.fyzk.activity.lottery.zc.ZCFX_view;
import com.tyjc.lottery.R;

import java.util.ArrayList;
import java.util.List;

public class ZuCai_FenXiActivity extends Activity{
	
	public static final String INFOR = "infor";
	
	//顶部
	private ImageView top_back;
	
	//选项卡
	private TextView tv_saishi,tv_zhenrong,tv_fenxi,tv_peilv;
	private ViewPager pager;
	private ZCFX_pagerAdapter vp_adapter = new ZCFX_pagerAdapter();
	private List<ZCFX_view> vp_views = new ArrayList<ZCFX_view>();
	
	private JCInfo infor;
	
	//内部类
	private ZCFX_onClick onClick = new ZCFX_onClick();
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		
		setContentView(R.layout.zc_fenxi);
		
		infor = (JCInfo) getIntent().getSerializableExtra(INFOR);
		
		info();
	}
	
	protected void onStart() {
		super.onStart();
		
		getInfors();
	};
	
	Handler handler = new Handler(){
		public void handleMessage(android.os.Message msg) {
			switch (msg.what) {
			case 1:
				
				getSS_infors();
				
				getZR_infors();
				
				getFX_infors();
				
				getPL_infors();
				
				break;

			default:
				break;
			}
		};
	};
	
	/**
	 * 初始化控件
	 */
	private void info(){
		//顶部
		top_back = (ImageView)findViewById(R.id.zcfx_title_iv_back);
		
		//选项卡
		tv_saishi = (TextView)findViewById(R.id.zcfx_xxk_tv_ss);
		tv_zhenrong = (TextView)findViewById(R.id.zcfx_xxk_tv_zr);
		tv_fenxi = (TextView)findViewById(R.id.zcfx_xxk_tv_fx);
		tv_peilv = (TextView)findViewById(R.id.zcfx_xxk_tv_pl);
		
		pager = (ViewPager)findViewById(R.id.zcfx_bottom_vp);
		for (int i = 0; i < 4; i++) {
			
			ZCFX_view view = new ZCFX_view(this,i);
			
			vp_views.add(view);
			
		}
		pager.setAdapter(vp_adapter);
		pager.setOnPageChangeListener(new ZCFX_PagerChange());
		
		//事件
		top_back.setOnClickListener(onClick);
		
		tv_saishi.setOnClickListener(onClick);
		tv_zhenrong.setOnClickListener(onClick);
		tv_fenxi.setOnClickListener(onClick);
		tv_peilv.setOnClickListener(onClick);
		
	}
	
	/**
	 * 获取数据
	 */
	private void getInfors(){
		//联网获取数据
		Message message = new Message();
		message.what = 1;
		
		
		handler.sendMessage(message);
		
	}
	
	/**
	 * 得到赛事数据
	 */
	private void getSS_infors(){
		List<List<Object>> group = new ArrayList<List<Object>>();
		List<Object> child1 = new ArrayList<Object>();
		for (int i = 0; i < 5; i++) {
			
//			child1.add(null);
		}
		List<Object> child2 = new ArrayList<Object>();
		for (int i = 0; i < 8; i++) {
			
//			child2.add(null);
		}
		
		group.add(child1);
		group.add(child2);
		
		vp_views.get(0).setList(group);
	}
	
	/**
	 * 得到阵容数据
	 */
	private void getZR_infors(){
		List<List<Object>> group = new ArrayList<List<Object>>();
		List<Object> child1 = new ArrayList<Object>();
		for (int i = 0; i < 5; i++) {
			
//			child1.add(null);
		}
		List<Object> child2 = new ArrayList<Object>();
		for (int i = 0; i < 8; i++) {
			
//			child2.add(null);
		}
		List<Object> child3 = new ArrayList<Object>();
		for (int i = 0; i < 8; i++) {
			
//			child2.add(null);
		}
		List<Object> child4 = new ArrayList<Object>();
		for (int i = 0; i < 8; i++) {
			
//			child2.add(null);
		}
		group.add(child1);
		group.add(child2);
		group.add(child3);
		group.add(child4);
		
		vp_views.get(1).setList(group);
	}

	/**
	 * 得到分析数据(待修改)
	 */
	private void getFX_infors(){
		List<List<Object>> group = new ArrayList<List<Object>>();
		List<Object> child1 = new ArrayList<Object>();
		for (int i = 0; i < 5; i++) {
			if (i == 0) {
				
				ZCFX_fx_lsjf lsjf = new ZCFX_fx_lsjf(1,"荷乙", "13-12-05", "奥斯", "1:2", "马斯特里赫特", "0:1");
				child1.add(lsjf);
			}else{
				ZCFX_fx_lsjf lsjf = new ZCFX_fx_lsjf(3,"荷乙", "13-12-05", "奥斯", "1:2", "马斯特里赫特", "0:1");
				child1.add(lsjf);
			}
		}
		List<Object> child2 = new ArrayList<Object>();
		for (int i = 0; i < 12; i++) {
			if (i == 0 || i == 6) {
				
				ZCFX_fx_lsjf lsjf = new ZCFX_fx_lsjf(2,"荷乙2", "13-12-05", "奥斯2", "1:2", "马斯特里赫特", "0:1");
				child2.add(lsjf);
			}else if(i == 1 || i == 7){
				ZCFX_fx_lsjf lsjf = new ZCFX_fx_lsjf(1,"荷乙2", "13-12-05", "奥斯2", "1:2", "马斯特里赫特", "0:1");
				child2.add(lsjf);
			}else if(i == 5 || i == 11){
				ZCFX_fx_lsjf lsjf = new ZCFX_fx_lsjf(0,"荷乙2", "13-12-05", "奥斯2", "1:2", "马斯特里赫特", "0:1");
				child2.add(lsjf);
			}else{
				ZCFX_fx_lsjf lsjf = new ZCFX_fx_lsjf(3,"荷乙2", "13-12-05", "奥斯2", "1:2", "马斯特里赫特", "0:1");
				child2.add(lsjf);
			}
		}
		List<Object> child3 = new ArrayList<Object>();
		for (int i = 0; i < 10; i++) {
			if (i == 0 || i == 5) {
				
				ZCFX_fx_lsjf lsjf = new ZCFX_fx_lsjf(2,"荷乙3", "13-12-05", "奥斯3", "1:2", "马斯特里赫特3", "0:1");
				child3.add(lsjf);
			}else if(i == 1 || i == 6){
				ZCFX_fx_lsjf lsjf = new ZCFX_fx_lsjf(1,"荷乙3", "13-12-05", "奥斯3", "1:2", "马斯特里赫特3", "0:1");
				child3.add(lsjf);
			}else{
				ZCFX_fx_lsjf lsjf = new ZCFX_fx_lsjf(3,"荷乙3", "13-12-05", "奥斯23", "1:2", "马斯特里赫3特", "0:1");
				child3.add(lsjf);
			}
		}
		List<Object> child4 = new ArrayList<Object>();
		for (int i = 0; i < 10; i++) {
			if (i == 0 || i == 5) {
				
				ZCFX_fx_lsjf lsjf = new ZCFX_fx_lsjf(2,"荷乙4", "13-12-05", "奥斯4", "1:2", "马斯特里赫特3", "0:1");
				child4.add(lsjf);
			}else if(i == 1 || i == 6){
				ZCFX_fx_lsjf lsjf = new ZCFX_fx_lsjf(1,"荷乙4", "13-12-05", "奥斯4", "1:2", "马斯特里赫特3", "0:1");
				child4.add(lsjf);
			}else{
				ZCFX_fx_lsjf lsjf = new ZCFX_fx_lsjf(3,"荷乙4", "13-12-05", "奥斯4", "1:2", "马斯特里赫3特", "0:1");
				child4.add(lsjf);
			}
//			child2.add(null);
		}
		group.add(child1);
		group.add(child2);
		group.add(child3);
		group.add(child4);
		
		vp_views.get(2).setList(group);
	}

	/**
	 * 得到赔率数据
	 */
	private void getPL_infors(){
		List<List<Object>> group = new ArrayList<List<Object>>();
		List<Object> child1 = new ArrayList<Object>();
		for (int i = 0; i < 5; i++) {
			
//			child1.add(null);
		}
		List<Object> child2 = new ArrayList<Object>();
		for (int i = 0; i < 8; i++) {
			
//			child2.add(null);
		}
		
		group.add(child1);
		group.add(child2);
		
		vp_views.get(3).setList(group);
	}
	
	
	
	/**
	 * 选项卡选择
	 * @param id
	 */
	private void check_xuanXiangKa(int id){
		switch (id) {
		case 0:
			tv_saishi.setBackgroundResource(R.drawable.sort_bg_selected);
			tv_zhenrong.setBackgroundResource(R.drawable.sort_bg_normal);
			tv_fenxi.setBackgroundResource(R.drawable.sort_bg_normal);
			tv_peilv.setBackgroundResource(R.drawable.sort_bg_normal);
			
			tv_saishi.setTextColor(getResources().getColor(R.color.zcfx_xxk_tv_s));
			tv_zhenrong.setTextColor(getResources().getColor(R.color.zcfx_xxk_tv_n));
			tv_fenxi.setTextColor(getResources().getColor(R.color.zcfx_xxk_tv_n));
			tv_peilv.setTextColor(getResources().getColor(R.color.zcfx_xxk_tv_n));
			
			break;
		case 1:
			tv_saishi.setBackgroundResource(R.drawable.sort_bg_normal);
			tv_zhenrong.setBackgroundResource(R.drawable.sort_bg_selected);
			tv_fenxi.setBackgroundResource(R.drawable.sort_bg_normal);
			tv_peilv.setBackgroundResource(R.drawable.sort_bg_normal);
			
			tv_saishi.setTextColor(getResources().getColor(R.color.zcfx_xxk_tv_n));
			tv_zhenrong.setTextColor(getResources().getColor(R.color.zcfx_xxk_tv_s));
			tv_fenxi.setTextColor(getResources().getColor(R.color.zcfx_xxk_tv_n));
			tv_peilv.setTextColor(getResources().getColor(R.color.zcfx_xxk_tv_n));
			
			break;
		case 2:
			tv_saishi.setBackgroundResource(R.drawable.sort_bg_normal);
			tv_zhenrong.setBackgroundResource(R.drawable.sort_bg_normal);
			tv_fenxi.setBackgroundResource(R.drawable.sort_bg_selected);
			tv_peilv.setBackgroundResource(R.drawable.sort_bg_normal);
			
			tv_saishi.setTextColor(getResources().getColor(R.color.zcfx_xxk_tv_n));
			tv_zhenrong.setTextColor(getResources().getColor(R.color.zcfx_xxk_tv_n));
			tv_fenxi.setTextColor(getResources().getColor(R.color.zcfx_xxk_tv_s));
			tv_peilv.setTextColor(getResources().getColor(R.color.zcfx_xxk_tv_n));
			
			break;
		case 3:
			tv_saishi.setBackgroundResource(R.drawable.sort_bg_normal);
			tv_zhenrong.setBackgroundResource(R.drawable.sort_bg_normal);
			tv_fenxi.setBackgroundResource(R.drawable.sort_bg_normal);
			tv_peilv.setBackgroundResource(R.drawable.sort_bg_selected);
			
			tv_saishi.setTextColor(getResources().getColor(R.color.zcfx_xxk_tv_n));
			tv_zhenrong.setTextColor(getResources().getColor(R.color.zcfx_xxk_tv_n));
			tv_fenxi.setTextColor(getResources().getColor(R.color.zcfx_xxk_tv_n));
			tv_peilv.setTextColor(getResources().getColor(R.color.zcfx_xxk_tv_s));

			break;
		default:
			break;
		}
		
		pager.setCurrentItem(id);
	}
	
	/**
	 * 单击事件
	 * @author Administrator
	 *
	 */
	class ZCFX_onClick implements OnClickListener{

		@Override
		public void onClick(View v) {
			
			switch (v.getId()) {
			case R.id.zcfx_title_iv_back:
				ZuCai_FenXiActivity.this.finish();
				break;
			case R.id.zcfx_xxk_tv_ss:
				check_xuanXiangKa(0);
				break;
			case R.id.zcfx_xxk_tv_zr:
				check_xuanXiangKa(1);
				break;
			case R.id.zcfx_xxk_tv_fx:
				check_xuanXiangKa(2);
				break;
			case R.id.zcfx_xxk_tv_pl:
				check_xuanXiangKa(3);
				break;
			default:
				break;
			}
		}
		
	}

	/**
	 * pager  适配器
	 * @author Administrator
	 *
	 */
	class ZCFX_pagerAdapter extends PagerAdapter{

		@Override
		public int getCount() {
			
			return vp_views.size();
		}

		@Override
		public boolean isViewFromObject(View arg0, Object arg1) {
			
			return arg0 == arg1;
		}
		
		@Override
		public Object instantiateItem(ViewGroup container, int position) {
			
			
			
			
			container.addView(vp_views.get(position));
			return vp_views.get(position);
		}
		
		@Override
		public void destroyItem(ViewGroup container, int position, Object object) {
			
			ViewGroup container1 = (ViewGroup) container;
			container1.removeView(vp_views.get(position));
		}
	}
	
	/**
	 * viewPager 切换子界面事件
	 * @author Administrator
	 *
	 */
	class ZCFX_PagerChange implements OnPageChangeListener{
		

		@Override
		public void onPageScrollStateChanged(int arg0) {
			
		}

		@Override
		public void onPageScrolled(int arg0, float arg1, int arg2) {

		}

		@Override
		public void onPageSelected(int arg0) {
			check_xuanXiangKa(arg0);
		}
	}
	

}
